function Add_Export_Line() {

Export_Line_Name = document.getElementById( "Export_Line_Name" ).value;
Export_Line_Data = document.getElementById( "Export_Line_Data" ).value;

if ( Export_Line_Name == "" ) { alert( 'The Export Line must not be blank!' ); return false; }
if ( Export_Line_Data == "" ) { alert( 'The Export Line must not be blank!' ); return false; }

if ( Export_Line_Name.indexOf('#') !== -1 || Export_Line_Name.indexOf('|') !== -1 ) { alert( 'Display name must not contain hash or pipe symbols!'  ); return false; }
if ( Export_Line_Data.indexOf('#') !== -1 || Export_Line_Data.indexOf('|') !== -1 ) { alert( 'Display name must not contain hash or pipe symbols!'  ); return false; }

var prefService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
var Export_Line_List = prefService.getCharPref('extensions.Ultima.Export_Line_List');

var exists = Export_Line_Exists( Export_Line_Name , Export_Line_Data.slice(0,2) );

if (exists) {
var response = confirm('This will overwrite the existing Export Line, proceed?');
if (!response) return false;
if (response) window.close();
}

if (!exists) {

Export_Line_List += "|" + Export_Line_Name + "#" + Export_Line_Data ;
prefService.setCharPref( 'extensions.Ultima.Export_Line_List' , Export_Line_List );
window.close();

} else {
Update_Export_Line( Export_Line_Name , Export_Line_Data );
}

}


function Export_Line_Exists( Name , Data ) {

var prefService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
var Export_Line_List = prefService.getCharPref( 'extensions.Ultima.Export_Line_List' ).split('|');

for(q=0; q<Export_Line_List.length; q++) {
var entry = Export_Line_List[q].split('#');

if (( Name == entry[0] )&&( Data == entry[1].slice(0,2) )) return true;

}
return false;

}


function Update_Export_Line( Export_Line_Name , Export_Line_Data ) {

var prefService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
var Export_Line_List = prefService.getCharPref( 'extensions.Ultima.Export_Line_List' ).split('|');

for(q=0; q<Export_Line_List.length; q++) {

var Entry = Export_Line_List[q].split('#');

if (( Export_Line_Name == Entry[0] )&&( Export_Line_Data.slice(0,2) == entry[1].slice(0,2) )) {

Entry[0] = Export_Line_Name ;
Entry[1] = Export_Line_Data ;

var Temp = Entry.join('#');

Export_Line_List[q] = Temp;

var Temp_Entry = Export_Line_List.join('|');

prefService.setCharPref( 'extensions.Ultima.Export_Line_List' , Temp_Entry );

}

}

}


function Check_For_Edit() {

if ( window.arguments[0] !== '' ) {

var Params = window.arguments[0];

document.getElementById( "Export_Line_Name" ).value = Params[0] ;
document.getElementById( "Export_Line_Data" ).value = Params[1] ;

}

}


function Task_Export_Line() {

var Export_Line_Data = document.getElementById( "Export_Line_Data" ).value;

var Export_Line_Data_Decrypted = Export_Line_Decryption( Export_Line_Data );

Export_Line_Data = Export_Line_Data_Decrypted.split('_');

if ( Export_Line_Data != "" ) {

document.getElementById( "Export_Line_Data_Decrypted" ).value = Export_Line_Data_Decrypted ;

if ( Export_Line_Data[2] ) {

var Export_Line_Name = ABC_Decryption( Export_Line_Data[2] );

if ( Export_Line_Data[4] ) if ( ( Export_Line_Data[3] != 0 )&&( Export_Line_Data[4] != 0 ) ) Export_Line_Name += " (" + Export_Line_Data[3] + ":" + Export_Line_Data[4] + ")" ;

document.getElementById( "Export_Line_Name" ).value = Export_Line_Name ;

}

}

}

function Task_Manager() {
Task_Export_Line();
setTimeout("Task_Manager()",1);
}

Task_Manager();